package com.qf.sys.service.impl;

import com.github.pagehelper.PageInfo;
import com.qf.sys.dao.RoleDao;
import com.qf.sys.po.Dept;
import com.qf.sys.po.Module;
import com.qf.sys.po.Role;
import com.qf.sys.po.RoleAuth;
import com.qf.sys.service.RoleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @创建人 sunsir Email:sunsir163@163.com
 * @创建时间 2022/5/8
 * @描述
 */
@Service
public class RoleServiceImpl implements RoleService {
    @Resource
    RoleDao roleDao;
    @Override
    public Role getRoleById(Integer id) {
        return roleDao.getRoleById(id);
    }

    @Override
    public PageInfo<Role> getRoleList(Map params) {
        List<Role> roleList= roleDao.getRoleList(params);
        PageInfo<Role> pageInfo = new PageInfo<Role>(roleList);
        return pageInfo;
    }

    @Override
    public boolean addRole(Map params) {
        return roleDao.addRole(params)>0;
    }

    @Override
    public boolean updateRole(Map params) {
        return roleDao.updateRole(params)>0;
    }

    @Override
    public boolean deleteRole(int id) {
        return roleDao.deleteRole(id)>0;
    }



    @Override
    public boolean addRoleAuth(int roleId, int[] moduleIds) {
        boolean f = true;
       roleDao.deleteRoleAuth(roleId);
       if(f==true){
          f=roleDao.addRoleAuth(roleId,moduleIds);
       }
        return f;
    }

    @Override
    public boolean upadteRolestatusTo0(int id) {
        return roleDao.upadteRolestatusTo0(id);
    }

    @Override
    public boolean upadteRolestatusTo1(int id) {
        return roleDao.upadteRolestatusTo1(id);
    }

    public List<Role> selectRoleList() {
        List<Role> roleList = roleDao.selectRoleList();
        System.out.println(roleList);
        return roleList;
    }

    @Override
    public List<Module> getModuleByRoleId(int roleId) {
        return roleDao.getModuleByRoleId(roleId);
    }


}
